<template>
  <div class="app-container calendar-list-container">
    <!--条件查询-->
    <div class="filter-container" style="margin-bottom: 5px">
      <el-row>
        <el-col :span="12">
          <el-button class="filter-item" size="small" style="margin-left: 10px;" @click="handleCreate" type="primary" icon="el-icon-edit">添加</el-button>
          <!-- <el-button class="filter-item" size="small" style="margin-left: 10px;" @click="handleDelete" type="primary" icon="el-icon-edit">删除</el-button> -->
          <el-button class="filter-item" size="small" style="margin-left: 10px;" @click="handleDisabled('disabled')" type="primary" icon="el-icon-edit">禁用</el-button>
          <el-button class="filter-item" size="small" style="margin-left: 10px;" @click="handleDisabled('enable')" type="primary" icon="el-icon-edit">启用</el-button>
          <el-button class="filter-item" size="small" style="margin-left: 10px;" @click="handleUpdate" type="primary" icon="el-icon-edit">编辑</el-button>
        </el-col>
        <el-col :span="12" style="text-align: right">
          <el-input @keyup.enter.native="handleFilter" size="small" style="width: 200px;" class="filter-item fsc-search"
                    placeholder="用户名称" v-model="listQuery.condition.name">
          </el-input>
          <el-button class="filter-item" size="small" type="primary" v-waves icon="el-icon-search"
                     @click="handleFilter">搜索
          </el-button>
          <el-button class="filter-item" size="small" type="primary" v-waves icon="el-icon-circle-plus-outline"
                     @click="moreCondition">更多
          </el-button>
          <!--<el-button class="filter-item" size="small" type="primary" v-waves icon="el-icon-search" @click="handleFilter">列选择</el-button>-->
          <el-dropdown trigger="click" :hide-on-click=false style="float: right;margin-left: 10px">
            <span class="el-dropdown-link">
              <el-button class="filter-item" size="small" type="primary" v-waves>
                选择列<i class="el-icon-arrow-down el-icon--right"></i>
              </el-button>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item>
                <el-checkbox-group v-model="checkColumnList">
                  <el-checkbox label="code">编码</el-checkbox>
                  <el-checkbox label="name">姓名</el-checkbox>
                  <el-checkbox label="mobile">手机号</el-checkbox>
                  <el-checkbox label="tel">联系电话</el-checkbox>
                  <el-checkbox label="email">电子邮箱</el-checkbox>
                  <el-checkbox label="gender">性别</el-checkbox>
                  <el-checkbox label="departmentName">所属部门</el-checkbox>
                </el-checkbox-group>
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
      <!--更多-->
      <div :class="{'search-transition':searchFlag,h0:true,hAuto:searchFlag,'search-content':true}">
        <el-form ref="form" :model="listQuery.condition" label-width="120px" :inline="true">
          <el-form-item label="手机号">
            <el-input placeholder="请输入手机号" class="w200" clearable v-model="listQuery.condition.mobile"></el-input>
          </el-form-item>
          <el-form-item label="用户编码">
            <el-input placeholder="请输入用户编码" class="w200" clearable v-model="listQuery.condition.code"></el-input>
          </el-form-item>
          <el-form-item label="使用状态">
            <el-select v-model="listQuery.condition.status" placeholder="请选择状态">
              <el-option label="未选择" value=""></el-option>
              <el-option label="正常" value="1"></el-option>
              <el-option label="失效" value="0"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="关联角色">
            <el-input placeholder="请输入关联角色" class="w200" clearable v-model="listQuery.condition.roleName"></el-input>
          </el-form-item>
          <el-form-item label="关联仓库">
            <el-input placeholder="请输入关联仓库" class="w200" clearable v-model="listQuery.condition.storeCode"></el-input>
          </el-form-item>
          <el-form-item label="关联发车点">
            <el-input placeholder="请输入关联发车点" class="w200" clearable v-model="listQuery.condition.deliveryCode"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="getList" style="margin-left: 10px">查询</el-button>
            <el-button type="primary" @click="reset">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>

    <!--列表-->
    <el-table ref="multipleTable" :data="list" v-loading="listLoading" element-loading-text="加载中"
              border fit highlight-current-row style="width: 100%" @selection-change="handleSelectionChange">
      <el-table-column  type="selection" width="55"></el-table-column>
      <el-table-column align="center" :width="value.width" v-for='(value,key) in columnList' :label="value.title" :key="key">
        <template slot-scope="scope">
          <div v-if="value.key === 'status'">{{scope.row[value.key] | userStatusFilter}}</div>
          <!--<div v-else-if="value.key === 'deliveryCode'">查看</div>-->
          <el-button type="text" size="mini" v-else-if="value.key === 'deliveryCode'" @click="handleToPrintDetail(scope.row[value.key])"
                     style="color: #409EFF; font-size: 12px;">关联发车点</el-button>
          <el-button type="text" size="mini" v-else-if="value.key === 'storeCode'" @click="handleToHouseDetail(scope.row[value.key])"
                     style="color: #409EFF; font-size: 12px;">关联仓库</el-button>
          <div v-else>{{scope.row[value.key]}}</div>
        </template>
      </el-table-column>
      <!-- <el-table-column align="center" label="操作" width="100" class-name="small-padding">
        <template slot-scope="scope">
          <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
        </template>
      </el-table-column> -->
      <el-table-column align="center" label="授权" width="250" class-name="small-padding">
        <template slot-scope="scope">
          <el-button type="primary" size="mini" @click="handleRoleGrant(scope.row)">角色</el-button>
          <el-button type="primary" size="mini" @click="handleHouseGrant(scope.row)">仓库</el-button>
          <el-button type="primary" size="mini" @click="handlePointGrant(scope.row)">发车点</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--分页-->
    <div v-show="!listLoading" class="pagination-container">
      <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page.sync="listQuery.current"
                     :page-sizes="[10,20,30, 50]" :page-size="listQuery.size" layout="total, sizes, prev, pager, next, jumper" :total="listQuery.total">
      </el-pagination>
    </div>

    <!--编辑弹出框-->
    <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" style="width: 80%">
      <el-form :rules="rules" ref="dataForm" :model="temp" label-position="right" label-width="100px" style='width: 40%; margin-left:50px;'>
        <el-form-item label="编码" prop="code">
          <el-input v-model="temp.code" placeholder="请输入机构编码"></el-input>
        </el-form-item>
        <el-form-item label="姓名" prop="name">
          <el-input v-model="temp.name" placeholder="请输入机构名称"></el-input>
        </el-form-item>
        <el-form-item label="密码" v-if="!passwordFlag" prop="password">
          <el-input v-model.trim="temp.password" placeholder="请输入密码" type="password" v-show="!passwordFlag" :enabled="!passwordFlag"></el-input>
        </el-form-item>
        <el-form-item label="确认密码" v-if="!passwordFlag"  prop="checkPassword">
          <el-input v-model.trim="temp.checkPassword" placeholder="请输入确认密码" type="password" v-show="!passwordFlag" :enabled="!passwordFlag"></el-input>
        </el-form-item>
        <el-form-item label="手机号" prop="mobile">
          <el-input v-model="temp.mobile"></el-input>
        </el-form-item>
        <el-form-item label="电子邮箱" prop="email">
          <el-input v-model="temp.email"></el-input>
        </el-form-item>
        <el-form-item label="性别" prop="gender">
          <el-radio-group v-model="temp.gender">
            <el-radio label="男" value="1"></el-radio>
            <el-radio label="女" value="0"></el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="所属部门" prop="department">
          <el-input v-model="temp.department"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button v-if="dialogStatus=='create'" @click="createData" type="primary" >确 定</el-button>
        <el-button v-else @click="updateData" type="primary">确 定</el-button>
      </div>
    </el-dialog>

    <!--角色授权弹出框-->
    <el-dialog title="角色授权" :visible.sync="dialogRoleVisible" :before-close="handleRoleClose">
      <el-table key="1" ref="roleMultipleTable" :data="roleList" v-loading="roleListLoading"
                element-loading-text="加载中" border fit highlight-current-row
                style="width: 99%" @selection-change="handleRoleSelectionChange">
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column align="center" label="序号" width="">
          <template slot-scope="scope">
            <span>{{scope.$index+1}}</span>
          </template>
        </el-table-column>
        <el-table-column width="" align="center" label="名称">
          <template slot-scope="scope">
            <span>{{scope.row.name}}</span>
          </template>
        </el-table-column>
        <el-table-column width="" align="center" label="标题">
          <template slot-scope="scope">
            <span>{{scope.row.title}}</span>
          </template>
        </el-table-column>
        <el-table-column width="" align="center" label="描述">
          <template slot-scope="scope">
            <span>{{scope.row.description}}</span>
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogRoleVisible = false">取 消</el-button>
        <el-button type="primary" @click="grantRoleData">确 定</el-button>
      </div>
    </el-dialog>

    <!--仓库授权弹出框-->
    <user-house-demo
      :edit_flag="dialogHouseVisible"
      :edit_main_title="userHouseTitle"
      :edit_select_row="userHouseSelectRow"
      ref="userHouseRef"
      @edit-close="grantHouseClose">
    </user-house-demo>

    <!--发车点授权弹出框-->
    <user-print-demo
      :edit_flag="dialogPointVisible"
      :edit_main_title="userPrintTitle"
      :edit_select_row="userPrintSelectRow"
      ref="userPrintRef"
      @edit-close="grantPointClose">
    </user-print-demo>
  
    <!--首页-关联发车点-列表弹窗-->
    <el-dialog title="已关联发车点列表" v-dialogDrag :visible.sync="dialogDeliveryCodeVisible"
               :before-close="handleDeliveryCodeClose" width="400px">
      <el-table  :data="deliveryCodeList"
                element-loading-text="加载中" border fit highlight-current-row>
        <!--<el-table-column type="selection" width="55"></el-table-column>-->
        <el-table-column align="center" label="序号" width="50">
          <template slot-scope="scope">
            <span>{{scope.$index+1}}</span>
          </template>
        </el-table-column>
        <el-table-column align="center" label="关联发车点" >
          <template slot-scope="scope">
            <span>{{scope.row}}</span>
          </template>
        </el-table-column>
      </el-table>
      <el-row type="flex" justify="end">
        <el-button type="primary" @click="dialogDeliveryCodeVisible = false">关闭</el-button>
      </el-row>
    </el-dialog>
    
    <!--首页-关联仓库-列表弹窗-->
    <el-dialog title="已关联仓库列表" v-dialogDrag :visible.sync="dialogStoreCodeVisible"
               :before-close="handleStoreCodeClose" width="400px">
      <el-table  :data="storeCodeList"
                 element-loading-text="加载中" border fit highlight-current-row>
        <!--<el-table-column type="selection" width="55"></el-table-column>-->
        <el-table-column align="center" label="序号" width="50">
          <template slot-scope="scope">
            <span>{{scope.$index+1}}</span>
          </template>
        </el-table-column>
        <el-table-column align="center" label="关联仓库" >
          <template slot-scope="scope">
            <span>{{scope.row}}</span>
          </template>
        </el-table-column>
      </el-table>
      <el-row type="flex" justify="end">
        <el-button type="primary" @click="dialogStoreCodeVisible = false">关闭</el-button>
      </el-row>
    </el-dialog>
  </div>
</template>

<script>
  import { queryPage, create, update, deleted, allRole, ownRole, grantRole, disableUserInfo } from '@/api/sys/sysuser'
  import waves from '@/directive/waves' // 水波纹指令
  import UserPrintDemo from './components/userPrintDemo'
  import UserHouseDemo from './components/userHouseDemo'
  const defaultFormThead = [
    { key: 'code', title: '用户编码', width: '' },
    { key: 'name', title: '用户名称', width: '' },
    { key: 'mobile', title: '手机号', width: '' },
    { key: 'roleName', title: '关联角色', width: '' },
    { key: 'deliveryCode', title: '关联发车点', width: '120' },
    { key: 'storeCode', title: '关联仓库', width: '120' },
    { key: 'tel', title: '座机号', width: '' },
    { key: 'email', title: '邮箱', width: '' },
    { key: 'gender', title: '性别', width: '' },
    { key: 'departmentName', title: '所属部门', width: '' },
    { key: 'status', title: '用户状态', width: '' }]
  export default {
    name: 'org',
    directives: {
      waves
    },
    components: { UserPrintDemo, UserHouseDemo },
    data() {
      return {
        columnList: defaultFormThead,
        checkColumnList: ['code', 'name', 'mobile', 'tel', 'email', 'gender', 'departmentName'],
        searchFlag: true,
        tableKey: 0,
        activeNames: ['1'],
        list: null,
        multipleSelection: [],
        listLoading: false,
        total: null,
        listQuery: {
          current: 1,
          size: 10,
          condition: {
            name: undefined,
            code: null,
            mobile: null,
            roleName: null,
            deliveryCode: null,
            storeCode: null,
            status: null
          }
        },
        temp: {
          id: undefined,
          code: '',
          name: '',
          mobile: '',
          email: '',
          gender: 1,
          department: undefined,
          password: '',
          checkPassword: ''
        },
        dialogFormVisible: false,
        dialogStatus: '',
        textMap: {
          update: '编辑用户',
          create: '创建用户'
        },
        rules: {
          code: [{ required: true, message: '编码不能为空', trigger: 'blur' }],
          name: [{ required: true, message: '名称不能为空', trigger: 'blur' }],
          mobile: [{ required: true, message: '手机号不能为空', trigger: 'blur' }],
          checkPassword: [{ required: true, message: '确认密码不能为空', trigger: 'blur' }],
          password: [{ required: true, message: '密码不能为空', trigger: 'blur' }]
        },
        roleList: null,
        houseList: null,
        pointList: null,
        dialogRoleVisible: false,
        dialogHouseVisible: false,
        dialogPointVisible: false,
        roleListLoading: false,
        houseListLoading: false,
        pointListLoading: false,
        userId: undefined,
        roleMultipleSelection: [],
        houseMultipleSelection: [],
        pointMultipleSelection: [],
        passwordFlag: false,
        dialogDeliveryCodeVisible: false, // 关联发车点列表 显示
        deliveryCodeList: [], // 关联发车点列表
        dialogStoreCodeVisible: false, // 关联仓库列表 显示
        storeCodeList: [], // 关联仓库列表
        userPrintTitle: '', // 发运点弹窗 标题
        userPrintSelectRow: {}, // 传入 发运点弹窗  首页选中row
        userHouseTitle: '',  // 仓库弹窗 标题
        userHouseSelectRow: {} // 传入 仓库弹窗  首页选中row
      }
    },
    created() {
      this.getList()
    },
    watch: {
      checkColumnList(valArr) {
        this.columnList = defaultFormThead.filter(v => {
          for (let i = 0; i < valArr.length; i++) {
            if (v.key === valArr[i]) {
              return v
            }
          }
        })
      }
    },
    methods: {
      handleChange() {
        console.log('更改了')
      },
      // 查询
      getList() {
        this.listLoading = true
        queryPage(this.listQuery).then(response => {
          this.listLoading = false
          this.list = response.data.records
          this.listQuery.total = response.data.total
        })
      },
      handleFilter() {
        this.listQuery.current = 1
        this.getList()
      },
      // 首页分页-size
      handleSizeChange(val) {
        this.listQuery.size = val
        this.getList()
      },
      // 首页分页-current
      handleCurrentChange(val) {
        this.listQuery.current = val
        this.getList()
      },
      // 首页-查询重置
      resetTemp() {
        this.temp = {
          id: undefined,
          code: '',
          name: '',
          mobile: '',
          tel: '',
          email: '',
          gender: 1,
          department: undefined
        }
      },
      handleCreate() {
        this.resetTemp()
        this.dialogStatus = 'create'
        this.dialogFormVisible = true
        this.passwordFlag = false
        this.$nextTick(() => {
          this.$refs['dataForm'].clearValidate()
        })
      },
      createData() {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            if (this.temp.checkPassword !== this.temp.password) {
              this.$notify({
                title: '警告',
                message: '密码和确认密码不一致',
                type: 'warning',
                duration: 2000
              })
              return
            }
            this.temp.houseId = this.$store.getters.currentStorehouse.id
            if (this.temp.gender === '男') {
              this.temp.gender = 1
            } else if (this.temp.gender === '女') {
              this.temp.gender = 0
            } else {
              this.temp.gender = null
            }
            create(this.temp).then(response => {
              if (response.code === 0) {
                this.$notify({
                  title: '成功',
                  message: '创建成功',
                  type: 'success',
                  duration: 2000
                })
                this.dialogFormVisible = false
                this.getList()
              }
            })
          }
        })
      },
      // 编辑
      handleUpdate() {
        const items = []
        this.multipleSelection.forEach(function(item, index, array) {
          items.push(item)
        })
        if (items.length > 1) {
          this.$notify({
            title: '警告',
            message: '只能选择单条编辑',
            type: 'warning',
            duration: 2000
          })
          return
        } else if (items.length < 1) {
          this.$notify({
            title: '警告',
            message: '请选择需要编辑的用户',
            type: 'warning',
            duration: 2000
          })
          return
        }
        console.info(items[0])
        this.temp = Object.assign({}, items[0]) // copy obj
        this.dialogStatus = 'update'
        this.dialogFormVisible = true
        this.passwordFlag = true
        this.$nextTick(() => {
          this.$refs['dataForm'].clearValidate()
        })
      },
      updateData() {
        this.$refs['dataForm'].validate((valid) => {
          console.log('updateData()1-valid', valid)
          if (valid) {
            console.log('updateData()2')
            if (this.temp.checkPassword !== this.temp.password) {
              this.$notify({
                title: '警告',
                message: '密码和确认密码不一致',
                type: 'warning',
                duration: 2000
              })
              return
            }
            console.log('updateData()')
            const tempData = Object.assign({}, this.temp)
            // tempData.timestamp = +new Date(tempData.timestamp) // change Thu Nov 30 2017 16:41:05 GMT+0800 (CST) to 1512031311464
            update(tempData).then(() => {
              // for (const v of this.list) {
              //   if (v.id === this.temp.id) {
              //     const index = this.list.indexOf(v)
              //     this.list.splice(index, 1, this.temp)
              //     break
              //   }
              // }
              this.dialogFormVisible = false
              this.getList()
              this.$notify({
                title: '成功',
                message: '更新成功',
                type: 'success',
                duration: 2000
              })
            })
          }
        })
      },
      // 删除
      handleDelete() {
        const ids = []
        this.multipleSelection.forEach(function(item, index, array) {
          ids.push(item.id)
        })
        deleted(ids).then(response => {
          if (response.code === 0) {
            // for (var i = 0; i < ids.length; i++) {
            //   this.removeList(ids[i])
            // }
            this.getList()
            this.$notify({
              title: '成功',
              message: '删除成功',
              type: 'success',
              duration: 2000
            })
          } else {
            this.$notify({
              title: '失败',
              message: response.message,
              type: 'fail',
              duration: 2000
            })
          }
        })
      },
      // type 0 禁用 or type 1  启用
      handleDisabled(type) {
        const that = this
        if (that.checkSelect(that.multipleSelection)) {
          const userIds = []
          let msg = ''
          if (type === 'disabled') {
            msg = '【失效】用户状态，不能再禁用'
            if (that.checkIsEnable(that.multipleSelection, '0', 'status', msg)) {
              this.$prompt('请输入禁用的原因', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                inputPlaceholder: '请输入禁用原因',
                inputPattern: /\s*\S+?/,
                inputErrorMessage: '请输入禁用原因'
              }).then(({ value }) => {
                that.multipleSelection.forEach((item) => {
                  userIds.push(item.id)
                })
                disableUserInfo({ userIds: userIds, type: '0', remark: value }).then(response => {
                  if (response.code === 0) {
                    that.getList()
                    that.$notify({
                      title: '成功',
                      message: '禁用成功',
                      type: 'success',
                      duration: 2000
                    })
                  } else {
                    that.$notify({
                      title: '失败',
                      message: response.message,
                      type: 'fail',
                      duration: 2000
                    })
                  }
                })
              }).catch(() => {
                this.$message({
                  type: 'info',
                  message: '取消输入'
                })
              })
            }
          } else if (type === 'enable') {
            msg = '【正常】用户状态，不能再启用'
            if (that.checkIsEnable(that.multipleSelection, '1', 'status', msg)) {
              that.multipleSelection.forEach((item) => {
                userIds.push(item.id)
              })
              disableUserInfo({ userIds: userIds, type: '1' }).then(response => {
                if (response.code === 0) {
                  that.getList()
                  that.$notify({
                    title: '成功',
                    message: '启用成功',
                    type: 'success',
                    duration: 2000
                  })
                } else {
                  that.$notify({
                    title: '失败',
                    message: response.message,
                    type: 'fail',
                    duration: 2000
                  })
                }
              })
            }
          }
        }
      },
      // 检验 数组(arr) 某参数(key) 是否 有匹配到相同的 状态数值(type)
      checkIsEnable(arr, type, key, msg) {
        const now_arr = arr
        const now_msg = msg
        for (const k in now_arr) {
          const cc = parseInt(now_arr[k][key])
          if (cc === parseInt(type)) {
            this.$message({
              message: now_msg,
              type: 'warning',
              duration: 2000
            })
            return false
          }
        }
        return true
      },
      removeList(id) {
        const index = this.list.findIndex(d => d.id === id)
        this.list.splice(index, 1)
      },
      // 关联发车点明细 弹窗打开
      handleToPrintDetail(prints) {
        if (prints) {
          this.deliveryCodeList = prints.split(',')
          if (this.deliveryCodeList && this.deliveryCodeList.length > 0) {
            this.dialogDeliveryCodeVisible = true
          } else {
            this.$message({
              message: '暂未关联发车点',
              type: 'warning',
              duration: 2000
            })
          }
        } else {
          this.$message({
            message: '暂未关联发车点',
            type: 'warning',
            duration: 2000
          })
        }
      },
      //  关联发车点明细 弹窗关闭
      handleDeliveryCodeClose() {
        this.dialogDeliveryCodeVisible = false
      },
      // 关联仓库明细 弹窗打开
      handleToHouseDetail(houses) {
        if (houses) {
          this.storeCodeList = houses.split(',')
          if (this.storeCodeList && this.storeCodeList.length > 0) {
            this.dialogStoreCodeVisible = true
          } else {
            this.$message({
              message: '暂未关联仓库',
              type: 'warning',
              duration: 2000
            })
          }
        } else {
          this.$message({
            message: '暂未关联仓库',
            type: 'warning',
            duration: 2000
          })
        }
      },
      //  关联仓库明细 弹窗关闭
      handleStoreCodeClose() {
        this.dialogStoreCodeVisible = false
      },
      // 首页行选中
      handleSelectionChange(val) {
        this.multipleSelection = val
      },
      // 角色弹窗打开
      handleRoleGrant(row) {
        this.userId = row.id
        this.dialogRoleVisible = true
        allRole().then(response => {
          this.roleList = response.data
          ownRole(row.id).then(response => {
            const ownIds = response.data
            if (ownIds !== null) {
              for (let i = 0; i < ownIds.length; i++) {
                this.toggleRoleRows(ownIds[i])
              }
            } else {
              this.$refs.roleMultipleTable.clearSelection()
            }
          })
          this.roleListLoading = false
        })
      },
      // 仓库弹窗打开
      handleHouseGrant(row) {
        this.userId = row.id
        this.userHouseSelectRow = row
        this.userHouseTitle = '仓库授权'
        this.dialogHouseVisible = true
        // allHouse().then(response => {
        //   this.houseList = response.data
        //   ownHouse(row.id).then(response => {
        //     const ownIds = response.data
        //     if (ownIds !== null) {
        //       for (let i = 0; i < ownIds.length; i++) {
        //         this.toggleHouseRows(ownIds[i])
        //       }
        //     } else {
        //       this.$refs.houseMultipleTable.clearSelection()
        //     }
        //   })
        //   this.houseListLoading = false
        // })
      },
      // 发运点弹窗打开
      handlePointGrant(row) {
        this.userId = row.id
        this.userPrintSelectRow = row
        this.userPrintTitle = '发运点授权'
        this.dialogPointVisible = true
        // allPoint().then(response => {
        //   const tempPointList = response.data
        //   ownPoint(row.id).then(response => {
        //     const ownPoints = response.data
        //     if (ownPoints !== null) {
        //       for (let i = 0; i < ownPoints.length; i++) {
        //         this.togglePointRows(tempPointList, ownPoints[i])
        //       }
        //       this.pointList = tempPointList
        //       this.$nextTick(() => {
        //         for (var i = 0, n = this.pointList.length; i < n; i++) {
        //           if (this.pointList[i].isown === 1) {
        //             this.$refs.pointMultipleTable.toggleRowSelection(this.pointList[i])
        //           }
        //         }
        //       })
        //       console.info(this.pointList)
        //     } else {
        //       this.$refs.pointMultipleTable.clearSelection()
        //     }
        //   })
        //   this.pointListLoading = false
        // })
      },
      toggleRoleRows(id) {
        if (this.roleList !== null) {
          for (let i = 0; i < this.roleList.length; i++) {
            if (this.roleList[i].id === id) {
              this.$refs.roleMultipleTable.toggleRowSelection(this.roleList[i])
            }
          }
        }
      },
      grantRoleData() {
        const ids = []
        this.roleMultipleSelection.forEach(function(item, index, array) {
          ids.push(item.id)
        })
        grantRole(this.userId, ids).then(response => {
          if (response.code === 0) {
            this.dialogRoleVisible = false
            this.$notify({
              title: '成功',
              message: '角色分配成功',
              type: 'success',
              duration: 2000
            })
            this.$refs.roleMultipleTable.clearSelection()
          } else {
            this.$notify({
              title: '失败',
              message: response.message,
              type: 'fail',
              duration: 2000
            })
          }
        })
      },
      // 仓库 弹窗关闭
      grantHouseClose() {
        this.dialogHouseVisible = false
        this.getList()
      },
      // 发运点 弹窗关闭
      grantPointClose() {
        this.dialogPointVisible = false
        this.getList()
      },
      // 重置
      reset() {
        this.listQuery = {
          current: 1,
          size: 10,
          total: 0,
          condition: {
            name: undefined,
            code: null,
            mobile: null,
            status: null
          }
        }
        this.getList()
      },
      // 角色列表选中
      handleRoleSelectionChange(val) {
        this.roleMultipleSelection = val
      },
      // 角色弹窗关闭
      handleRoleClose(done) {
        this.$refs.roleMultipleTable.clearSelection()
        done()
      },
      // 检查是否选择单条
      checkSelect(data) {
        const l = data.length
        if (l === 0) {
          this.$message({
            message: '未选择',
            type: 'warning',
            duration: 2000
          })
          return false
        }
        // if (l > 1) {
        //   this.$message({
        //     message: ' 不可多选, 请选择单条!',
        //     type: 'warning',
        //     duration: 2000
        //   })
        //   return false
        // }
        return true
      },
      moreCondition() {
        this.searchFlag = !this.searchFlag
      }
    }
  }
</script>

<style scoped>
</style>
